package com.pcbly.web.components.utils;

import java.text.DateFormat;
import java.util.Calendar;

public class AnnualCountUtils {
	private static float[] lowOffshoreAnnualDays = { 5f, 4.5f, 4f, 3.5f, 3f, 2.5f, 2f,
			1.5f, 1f, 0.5f, 0.5f, 0f };// if you need get data from
	// database,please add method read
	// database

	private static float[] managerOffshoreAnnualDays = { 7f, 6.5f, 6f, 5.5f, 5f, 4f,
			3f, 2.5f, 2f, 1.5f, 1f, 0f };// if you need get data from
	// database,please add method read
	// database

	private static float defaultOffshoreLowAnnualDay = 5f;// if you need get data from
	// database,please add
	// method read database

	private static float defaultOffshoreManagerAnnualDay = 7f;// if you need get data
	// from database,please
	// add method read
	// database
	private static float maxOffshoreAnnualDay = 15f;
	
	
	

	public static float getOffshoreNewEmployeeAnnualDay(String joindate,
			String level) {
		float refloat = 0f;
		if (!(joindate == null || "".equals(joindate.trim()))) {
			if ("".indexOf(level) >= 0) {// manager
				// I don't know How to get managerId from properties or
				// database?
				// this need you define these managerId.
				refloat = getOffshoreCurrentManagerCurrent(joindate);
			} else {
				refloat = getOffshoreCurrentEmployeeCurrent(joindate);
			}
		}
		return refloat;
	}

	private static float getOffshoreCurrentManagerCurrent(String joindate) {
		try {
			Calendar curCalendar = Calendar.getInstance();
			Calendar maCalendar = Calendar.getInstance();
			DateFormat df = DateFormat.getDateInstance();
			maCalendar.setTime(df.parse(joindate));
			int curYear = curCalendar.get(Calendar.YEAR);
			int maYear = maCalendar.get(Calendar.YEAR);
			if (curYear == maYear) {
				if (maCalendar.get(Calendar.DAY_OF_MONTH) > 15) {
					return managerOffshoreAnnualDays[maCalendar.get(Calendar.MONTH)];
				} else {
					return managerOffshoreAnnualDays[(maCalendar.get(Calendar.MONTH) + 1)];
				}
			} else {
				return 0f;
			}
		} catch (Exception e) {
			e.printStackTrace();
			return 0f;
		}
	}

	private static float getOffshoreCurrentEmployeeCurrent(String joindate) {
		try {
			Calendar curCalendar = Calendar.getInstance();
			Calendar maCalendar = Calendar.getInstance();
			DateFormat df = DateFormat.getDateInstance();
			maCalendar.setTime(df.parse(joindate));
			int curYear = curCalendar.get(Calendar.YEAR);
			int maYear = maCalendar.get(Calendar.YEAR);
			if (curYear == maYear) {
				if (maCalendar.get(Calendar.DAY_OF_MONTH) > 15) {
					return lowOffshoreAnnualDays[maCalendar.get(Calendar.MONTH)];
				} else {
					return lowOffshoreAnnualDays[(maCalendar.get(Calendar.MONTH) + 1)];
				}
			} else {
				return 0f;
			}
		} catch (Exception e) {
			e.printStackTrace();
			return 0f;
		}
	}

	private static float getOffshoreCurrentManagerAnuualCount(String joindate) {
		float refloat = 0f;
		try {
			Calendar curCalendar = Calendar.getInstance();
			Calendar maCalendar = Calendar.getInstance();
			DateFormat df = DateFormat.getDateInstance();
			maCalendar.setTime(df.parse(joindate));
			int curYear = curCalendar.get(Calendar.YEAR);
			int maYear = maCalendar.get(Calendar.YEAR);
			int desInt = curYear - maYear;
			refloat = defaultOffshoreManagerAnnualDay + Float.parseFloat("" + desInt);
			if (refloat > maxOffshoreAnnualDay) {
				refloat = maxOffshoreAnnualDay;
			}
		} catch (Exception e) {
			e.printStackTrace();
		}
		return refloat;
	}

	private static float getOffshoreCurrentEmployeeAnuualCount(String joindate) {
		float refloat = 0f;
		try {
			Calendar curCalendar = Calendar.getInstance();
			Calendar maCalendar = Calendar.getInstance();
			DateFormat df = DateFormat.getDateInstance();
			maCalendar.setTime(df.parse(joindate));
			int curYear = curCalendar.get(Calendar.YEAR);
			int maYear = maCalendar.get(Calendar.YEAR);
			int desInt = curYear - maYear;
			refloat = defaultOffshoreLowAnnualDay + Float.parseFloat("" + desInt);
			if (refloat > maxOffshoreAnnualDay) {
				refloat = maxOffshoreAnnualDay;
			}
		} catch (Exception e) {
			e.printStackTrace();
		}
		return refloat;
	}

	public static float getOffshoreCurrentAnuualCount(String joindate,
			String level) {
		float refloat = 0f;
		if (!(joindate == null || "".equals(joindate.trim()))) {
			if ("".indexOf(level) >= 0) {// manager
				// I don't know How to get managerId from properties or
				// database?
				// this need you define these managerId.
				refloat = getOffshoreCurrentManagerAnuualCount(joindate);
			} else {
				refloat = getOffshoreCurrentEmployeeAnuualCount(joindate);
			}
		}
		return refloat;
	}
	
//	private static float defaultOnshoreDays=0f;
	
}
